package com.example.demo.web.rest.controller;

import com.example.demo.client.evt.sysbasequery.LogStatisticEvt;
import com.example.demo.client.vm.sysbasequery.HistogramVm;
import com.example.demo.client.vm.sysbasequery.LogStatisticsDataVm;
import com.ffcs.oss.param.out.ServiceResp;
import com.example.demo.service.LogStatisticService;
import com.example.demo.web.rest.evt.ExportLogStatisticEvt;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;

/**
 * 日志统计
 * @Author zhengmf
 * @Date 2019/1/14  17:07
 */
@ApiModel(description ="日志统计接口")
@RestController
@RequestMapping(value = "/api/logStatistic")
public class LogStatisticsController extends BaseController{
    @Autowired
    private LogStatisticService logStatisticService;

    @ApiOperation("获取日志统计数据")
    @PostMapping(value = "/getLogStatisticsData")
    public ServiceResp<LogStatisticsDataVm> getLogStatisticsData(){
        return baseQueryClient.getLogStatisticsData();
    }

    @ApiOperation("用户个人功能使用TOP10下钻数据")
    @PostMapping(value = "/getUserFunctionUseTop10Drill")
    public ServiceResp<HistogramVm> getUserFunctionUseTop10Drill(@RequestBody LogStatisticEvt evt){
        return baseQueryClient.getUserFunctionUseTop10Drill(evt);
    }

    @ApiOperation("系统功能TOP10使用下钻数据")
    @PostMapping(value = "/getFunctionUseTop10Drill")
    public ServiceResp<HistogramVm> getFunctionUseTop10Drill(@RequestBody LogStatisticEvt evt){
        return baseQueryClient.getFunctionUseTop10Drill(evt);
    }

    @ApiOperation("日志统计导出")
    @GetMapping("/exportLogStatistic")
    public void exportLogStatistic(HttpServletResponse response, ExportLogStatisticEvt evt){
        try {
            if(evt.isExportAll()){
                export(response,logStatisticService.allDataWorkbook(),"所有图标数据");
            }else {
                export(response,logStatisticService.selectedDataWorkbook(evt.getLogStatisticTitle()),"选中图标数据");
            }
        } catch (Exception e) {
            logger.error("操作日志导出异常：" + e.getMessage());
            e.printStackTrace();
        }
    }

}
